//
//  DynamicTrainCell.m
//  liangyi
//
//  Created by 张水 on 16/12/26.
//  Copyright © 2016年 yswh. All rights reserved.
//

#import "DynamicTrainCell.h"
#import "AppHeader.h"
@implementation DynamicTrainCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

-(void)setModel:(DynamicTrainModel *)model{
    
    _model = model;
    
    [self.IconImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",BaseIamgeUrl,model.userHead]] placeholderImage:[UIImage imageNamed:@"user"]];
    self.userNameLabel.text = model.userName;
//    NSString *time = [NSString timeWithTimeIntervalString:model.createTime];
    
    self.timeLabel.text = [NSString timeWithTimeIntervalString:model.createTime];
    self.commentLabel.text = model.content;
    StageModel *stage = [StageModel mj_objectWithKeyValues:model.stage];
    if (stage.num == nil){
        self.userSectionLabel.text = @"正在观看此视频";
    }else if ([stage.num intValue]>1){
        self.userSectionLabel.text = [NSString stringWithFormat:@"完成第%d阶段训练",[stage.num intValue] - 1];
    }else{
        self.userSectionLabel.text = [NSString stringWithFormat:@"进行第%@阶段训练",stage.num];
    }
}


- (void)setupUI{
    self.backgroundColor = [UIColor whiteColor];
    
    self.IconImage = [[UIImageView alloc]init];
    self.IconImage.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:self.IconImage];
    [self.IconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(5);
        make.left.equalTo(self.contentView).offset(10);
        make.width.height.equalTo(@50);
    }];
    self.IconImage.layer.masksToBounds = YES;
    self.IconImage.layer.cornerRadius = 25;
    self.IconImage.layer.borderColor = [UIColor ColorWithHex:@"#5BC2D2"].CGColor;
    self.IconImage.layer.borderWidth = 1;
    
    
    self.userNameLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.userNameLabel];
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.IconImage.mas_right).offset(10);
        make.centerY.equalTo(self.IconImage.mas_centerY);
    }];
    self.userNameLabel.textColor = [UIColor ColorWithHex:@"#686868"];
    self.userNameLabel.textAlignment = NSTextAlignmentLeft;
    self.userNameLabel.font = [UIFont systemFontOfSize:15];
    
    self.timeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.centerY.equalTo(self.IconImage.mas_centerY);
    }];
    self.timeLabel.textColor = [UIColor ColorWithHex:@"#8a8989"];
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel.font = [UIFont systemFontOfSize:10];
    
    
    self.commentLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.commentLabel];
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.IconImage.mas_bottom).offset(5);
        make.left.equalTo(self.IconImage.mas_left);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.height.equalTo(@50);
    }];
    self.commentLabel.textColor = [UIColor ColorWithHex:@"#282828"];
    self.commentLabel.textAlignment = NSTextAlignmentLeft;
    self.commentLabel.font = [UIFont systemFontOfSize:14];
    
    
    self.backView  = [[UIView alloc]init];
    [self.contentView addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.commentLabel.mas_bottom).offset(3);
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.height.equalTo(@40);
    }];
    self.backView.backgroundColor = [UIColor ColorWithHex:@"#f8f8f8"];
    
    self.imgView = [[UIImageView alloc]init];
    [self.backView addSubview:self.imgView];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.backView.mas_centerY);
        make.left.equalTo(self.backView).offset(10);
        make.width.height.equalTo(@30);
    }];
    self.imgView.image = [UIImage imageNamed:@"succeed"];
    
    self.userSectionLabel = [[UILabel alloc]init];
    [self.backView addSubview:self.userSectionLabel];
    [self.userSectionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.backView.mas_centerY);
        make.left.equalTo(self.imgView.mas_right).offset(10);
    }];
    self.userSectionLabel.font = [UIFont systemFontOfSize:15];
    self.userSectionLabel.textColor = [UIColor ColorWithHex:@"#b0b0b0"];
    self.userSectionLabel.textAlignment = NSTextAlignmentLeft;
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
}



@end
